package com.example.mqttcar.controller;

import com.example.mqttcar.mqtt.MqttSubscriber;
import com.example.mqttcar.websocket.WebSocketServer;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/websocket")
public class WebSocketSendController {
    @Resource
    private WebSocketServer webSocketServer;


    @RequestMapping("/send")
    public String sendMessage(@RequestBody String message) throws Exception {
        webSocketServer.sendToSpecificUser(message,"1","mqtt-car");
        return "消息已发送: " + message;
    }
}
